require(['../config/requireconfig'], function (config) {
    //根据需要添加
    require(['zepto', 'common/mcommon', 'swiper'], function ($, com, swiper) {
        com.init();
        var pageLogic = new PageLogic($, com, swiper);
        pageLogic.init();

    });
});
// function back(type) {

// };
var PageLogic = function ($, com, Swiper) {
    return {
        init: function () {
            var _this = this;
            var brandName = com.utils().urlParam("brandName");
            var modelName = com.utils().urlParam("modelName");
            var vim = com.utils().urlParam("vim");
            if ((!brandName || !modelName) & !vim) {
                com.utils().windowJump("/");
            }
            _this.initData();
            // _this.initVichileData();
            _this.bindEvent();
        },
        noString: function (string) {
            if (!string) {
                return "-";
            }
            return string;
        },
        bindEvent: function () {
            var _this = this;
            $("#selvol").on("change", function () {
                _this.initVichileData();
            });
            $('.back').on("click", function () {
                if (com.utils().urlParam("brandName")) {
                    com.utils().windowJump("prodGasDetail.htm?brandName=" + com.utils().urlParam("brandName") + "&modelName=" + com.utils().urlParam("modelName"));
                } else {
                    com.utils().windowJump("prodGas.htm");
                }
            })
            $("#bg").on("click", function () {
                $('#bg').css('display', 'none');
                $('#model').css('display', 'none');
            })
            $(".closeWhite").on("click", function () {
                $('#bg').css('display', 'none');
                $('#model').css('display', 'none');
            })
            $('.Loadphoto').on("click", function () {
                let str = $(this).attr('imgData')
                if (str == "") {
                    com.toast("暂无图片");
                    return;
                } else {
                    $("#bg").css('display', 'block')
                    $("#model").css('display', 'block')
                    let text = $(this).parent().siblings().text();
                    $("#model .text").text(text);
                    let html = "";
                    let arr = str.split("/")
                    $(arr).each(function (index, item) {

                        html += '<div class="swiper-slide ">';
                        html+='<span class="img"></span>'
                        html += ' <img src="' + com.Config.domainGas + item + '.png" >';
                        html += '</div>';

                    });
                    $(".swiper-wrapper").empty();
                    $(".swiper-wrapper").append(html);
                    $('.swiper-slide img').click(function (e) {
                        $('.modelImg').css('display', 'block')
                        $("#model").css('display', 'none')
                        $('.modelImg img').attr('src', $(this).attr('src'))
                        $('.modelImg img').click(function () {
                            $('.modelImg').hide();
                            $("#model").css('display', 'block');
                        })
                        $('#bg').click(function () {
                            $('.modelImg').hide();
                            $("#bg").css('display', 'none');
                        })
                    });
                    swiper = null
                    var swiper = new Swiper('#swiperWrap', {
                        lazy: true,
                        direction: 'horizontal',
                        initialSlide: 0,
                        observer: true,//修改swiper自己或子元素时，自动初始化swiper
                        observeParents: true,//修改swiper的父元素时，自动初始化swiper
                        navigation: {
                            nextEl: '.swiper-button-next',
                            prevEl: '.swiper-button-prev',
                        },
                        pagination: {
                            el: '.swiper-pagination'
                        },
                    });
                }


            })

        },
        params: function () {
            var _this = this;
            var obj = `brand=${com.utils().urlParam("brandName")}&vehicletype=${com.utils().urlParam("modelName")}&vehiclDate=${com.utils().urlParam("vehiclDate")}&displacementL=${com.utils().urlParam("displacementL")}&transmissionType=${com.utils().urlParam("transmissionType")}&stalls=${com.utils().urlParam("stalls")}&transmissionDescription=${com.utils().urlParam("transmissionDescription")}`;
            return obj;
        },
        loadData: function (data) {
            var _this = this;

            $("td[attr='brand']").html(data.brand)
            _this.noString(data)

            if (data.extInfos.length == 0) {
                autogearbox = "-"
            } else {
                autogearbox = '';
                let arr = data.extInfos[0].autogearbox.split('/');
                let str1 = arr[0];
                let str2 = arr[1];
                data.extInfos.forEach(function (item, index) {
                    if (index == 0) {
                        autogearbox += `${str1}</br>规格:${item.standard}L 零件号:${item.partNo}<br>`

                    } else if (index == 2) {
                        autogearbox += `${str2}</br>规格:${item.standard}L 零件号:${item.partNo}<br>`

                    } else {
                        autogearbox += `规格:${item.standard}L 零件号:${item.partNo}<br>`

                    }
                });
            }

            $("td[attr='vehicletype']").html(_this.noString(data.vehicletype))
            $("td[attr='drivingMode']").html(_this.noString(data.drivingMode))
            $("td[attr='transmissionType']").html(_this.noString(data.transmissionType))
            $("td[attr='transmissionDescription']").html(_this.noString(data.transmissionDescription))
            $("td[attr='autogearbox']").html(_this.noString(autogearbox))
            $("td[attr='gearboxType']").html(_this.noString(data.gearboxType))
            $("td[attr='oilChange']").html(_this.noString(data.oilChange))
            $("td[attr='remarks']").html(data.remarks);
            $("td[attr='stalls']").html(_this.noString(data.stalls))
            $("span[attr='changeJointSpan']").html(data.changeJoint)
            $("span[attr='changeJoint']").attr('imgdata', data.changeJoint)
            $("span[attr='jointlocation']").attr('imgdata', data.jointlocation)
            $("span[attr='oilcheck']").attr('imgdata', data.oilcheck)
            $("span[attr='changeProcess']").attr('imgdata', data.changeProcess)
            $("span[imgdata='']").each(function () {
                $(this).html('')

            })
        },
        initData: function () {
            var _this = this;
            if (com.utils().urlParam("vim")) {
                com.ajax({
                    url: "/getByVarialbleVinCode.json",
                    data: { vin: com.utils().urlParam("vim") },
                    success: function (res) {
                        console.log(res.data['carInfo'])
                        let data = res.data['carInfo']
                        _this.loadData(data)
                    }
                });
            } else {
                com.ajax({
                    url: "/getInfo.json",
                    data: _this.params(),
                    success: function (res) {
                        let data = res.data[0]
                        _this.loadData(data)

                    }
                });
            }

        },


    }

}